/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.faytechcc.csc.gui.search;

import edu.faytechcc.csc.messages.NetworkConnection;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * Please describe what this class does here.
 *
 * CSC 251 0001 DATE:
 *
 * @author Stephanie Mckenzie
 */
public class TopFivePanel extends JPanel
{

    private NetworkConnection conn = null;
    private SearchFrame searching;

    public TopFivePanel(SearchFrame search)
    {
        this.searching = search;
        this.conn = searching.getConn();
        this.setLayout(new GridLayout(5, 1));
        searching.setRandom(true);
        for (int index = 0; index < 5; index++)
        {
            conn.sendMessages("SELECT ENG_TITLE, PHOTO FROM Anime_Table ORDER BY RANDOM()");
        }
    }

    public void createButton(String title, String photo)
    {
        JButton randomButton = new JButton(title);
        randomButton.addActionListener(new RandomActionListener());
//        ImageIcon topFiveImage = new ImageIcon(photo);
//        randomButton.setIcon(topFiveImage);
        this.add(randomButton);
    }

    private class RandomActionListener implements ActionListener
    {

        @Override
        public void actionPerformed(ActionEvent e)
        {
            String title = e.getActionCommand();
            conn.sendMessages("SELECT * FROM Anime_Table"
                    + " WHERE ENG_TITLE = '" + title + "'");

        }
    }
}
